package locksupport.objectlock;

/**
 * @author ZhuQi
 * @ClassName LockSupportDemo
 * @Date 2022/9/13 13:40
 * @Version 1.0
 * @Description 测试 Object 的 waite 和 notify
 */
public class LockSupportDemo {

    public static void main(String[] args) {
        Object object = new Object();

        Thread thread1 = new Thread(() -> {
            synchronized (object) {
                System.out.println(Thread.currentThread().getName() + " wait");
                try {
                    object.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName() + " 唤醒");
            }
        }, "thread1");

        Thread thread2 = new Thread(() -> {
            synchronized (object) {
                object.notify();
            }
        }, "thread2");

        thread1.start();
        thread2.start();
    }
}
